/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the MatrixParser package.
 *  
 *  The MatrixParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.incparser.parsers;

import java.util.HashMap;
import java.util.Map;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorLabelled;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorLabelledNew;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorLabelledMartin;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorUnlabelled;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorUnlabelledMartin;
import org.osdtsystem.incparser.featureextraction.MstFeatureExtractorUnlabelledNew;
import org.osdtsystem.incparser.features.FeatureHandler;
import org.osdtsystem.incparser.graphs.ConllAdapter;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public abstract class AbstractMstParser extends AbstractConllParser {
    public static boolean martinsExtractors = false;

    Map<ConllAdapter,MstFeatureExtractorLabelled> mstLabelledExtractors
            = new HashMap<ConllAdapter,MstFeatureExtractorLabelled>();
    Map<ConllAdapter,MstFeatureExtractorUnlabelled> mstUnlabelledExtractors
            = new HashMap<ConllAdapter,MstFeatureExtractorUnlabelled>();

    public AbstractMstParser(FeatureHandler edgeTypeHandler, FeatureHandler stringHandler, FeatureHandler featureHandler) {
        super(edgeTypeHandler, stringHandler, featureHandler);
    }

    final MstFeatureExtractorLabelled labelledMstExtractor(ConllAdapter graph) {
        if (! mstLabelledExtractors.containsKey(graph))
            mstLabelledExtractors.put(graph, newLabelledMstExtractor(graph));
        return mstLabelledExtractors.get(graph);
    }

    MstFeatureExtractorLabelled newLabelledMstExtractor(ConllAdapter graph) {
        return martinsExtractors 
                ? new MstFeatureExtractorLabelledMartin(graph, featureHandler)
                : new MstFeatureExtractorLabelledNew(graph, featureHandler);
    }

    MstFeatureExtractorUnlabelled newUnlabelledMstExtractor(ConllAdapter graph) {
        return martinsExtractors
                ? new MstFeatureExtractorUnlabelledMartin(graph, featureHandler)
                : new MstFeatureExtractorUnlabelledNew(graph, featureHandler);
    }

    final MstFeatureExtractorUnlabelled unlabelledMstExtractor(ConllAdapter graph) {
        if (! mstUnlabelledExtractors.containsKey(graph))
            mstUnlabelledExtractors.put(graph, newUnlabelledMstExtractor(graph));
        return mstUnlabelledExtractors.get(graph);
    }
}
